package ch07_GUI编程;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

public class EventListenerWithAnonymouseInnerClass {
	JLabel tip = new JLabel("请单击下面的按钮");
	JButton b1 = new JButton("确定");
	JButton b2 = new JButton("取消");
	public static void main(String[] args) {
		new EventListenerWithAnonymouseInnerClass().init();
	}
	void init() {
		BaseFrame f = new BaseFrame("使用匿名内部类处理事件");
		f.setLayout(new FlowLayout());
		
		b1.addActionListener(new ActionListener() {    //创建了匿名类对象，实现了ActionListener接口
			public void actionPerformed(java.awt.event.ActionEvent e) {
				tip.setText("你单击了[" + b1.getText() + "]按钮");
			}
		});
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				tip.setText("你单击了[" + b2.getText() + "]按钮");
			}
		});
		f.add(tip);
		f.add(b1);
		f.add(b2);
		
		f.showMe();
	}
}
